package com.ruibang.glass.material.service.impl.fwk;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruibang.glass.material.domain.req.ycl.ManageOutBoundReq;
import com.ruibang.glass.material.domain.req.ycl.ManageOutInReq;
import com.ruibang.glass.material.dto.OutAndInManagementDTO;
import com.ruibang.glass.material.entity.fwk.MaterialFWKOutboundManagement;
import com.ruibang.glass.material.entity.ycl.MaterialOutboundManagement;
import com.ruibang.glass.material.mapper.fwk.GMaterialFWKOutboundManagementMapper;
import com.ruibang.glass.material.mapper.ycl.GMaterialOutboundManagementMapper;
import com.ruibang.glass.material.service.fwk.GMaterialFWKOutboundManagementService;
import com.ruibang.glass.material.service.ycl.GMaterialOutboundManagementService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 出库管理表 服务实现类
 * </p>
 *
 * @author mameng
 * @since 2024-04-01
 */
@Service
public class GMaterialFWKOutboundManagementServiceImpl extends
        ServiceImpl<GMaterialFWKOutboundManagementMapper, MaterialFWKOutboundManagement> implements GMaterialFWKOutboundManagementService {


    @Override
    public IPage<MaterialFWKOutboundManagement> getPage(ManageOutBoundReq materialInventoryReq) {
        LambdaQueryWrapper<MaterialFWKOutboundManagement> queryWrapper = Wrappers.<MaterialFWKOutboundManagement>lambdaQuery();
        if (StringUtils.isNotBlank(materialInventoryReq.getOrderNumber())) {
            queryWrapper.like(MaterialFWKOutboundManagement::getOrderNumber, materialInventoryReq.getOrderNumber());
        }
        if (StringUtils.isNotBlank(materialInventoryReq.getType())) {
            queryWrapper.like(MaterialFWKOutboundManagement::getType, materialInventoryReq.getType());
        }
        if (StringUtils.isNotBlank(materialInventoryReq.getStatus())) {
            queryWrapper.like(MaterialFWKOutboundManagement::getStatus, materialInventoryReq.getStatus());
        }
        if (StringUtils.isNotBlank(materialInventoryReq.getApproveStatus())) {
            queryWrapper.like(MaterialFWKOutboundManagement::getApproveStatus, materialInventoryReq.getApproveStatus());
        }
        if (StringUtils.isNotBlank(materialInventoryReq.getPreparer())) {
            queryWrapper.like(MaterialFWKOutboundManagement::getPreparer, materialInventoryReq.getPreparer());
        }
        if (StringUtils.isNotBlank(materialInventoryReq.getBatchNumber())) {
            queryWrapper.like(MaterialFWKOutboundManagement::getBatchNumber, materialInventoryReq.getBatchNumber());
        }
        if (StringUtils.isNotBlank(materialInventoryReq.getItemName())) {
            queryWrapper.like(MaterialFWKOutboundManagement::getItemName, materialInventoryReq.getItemName());
        }
        if (StringUtils.isNotBlank(materialInventoryReq.getBarcodeNumber())) {
            queryWrapper.like(MaterialFWKOutboundManagement::getBarcodeNumber, materialInventoryReq.getBarcodeNumber());
        }
        if (materialInventoryReq.getFinishStartDate() != null) {
            queryWrapper.ge(MaterialFWKOutboundManagement::getFinishDate, materialInventoryReq.getFinishStartDate());
        }
        if (materialInventoryReq.getFinishEndDate() != null) {
            queryWrapper.le(MaterialFWKOutboundManagement::getFinishDate, materialInventoryReq.getFinishEndDate());
        }
        Page<MaterialFWKOutboundManagement> materialWarehouseInfoPage = baseMapper.selectPage(new Page<>(materialInventoryReq.getPageNo(), materialInventoryReq.getPageSize()),
                queryWrapper.orderByDesc(MaterialFWKOutboundManagement::getCreateTime)
        );
        return materialWarehouseInfoPage;
    }

    @Override
    public IPage<OutAndInManagementDTO> getPage(ManageOutInReq manageOutInReq) {
        return baseMapper.getPage(new Page<>(manageOutInReq.hashCode(), manageOutInReq.getPageSize()), manageOutInReq);
    }
}
